//
//  SymbolUtils.m
//  LinkMap
//
//  Created by aron on 2022/5/9.
//  Copyright © 2022 ND. All rights reserved.
//

#import "SymbolUtils.h"

@implementation SymbolUtils

+ (NSArray *)sortSymbols:(NSArray *)symbols {
    NSArray *sortedSymbols = [symbols sortedArrayUsingComparator:^NSComparisonResult(ObjectResult *  _Nonnull obj1, ObjectResult *  _Nonnull obj2) {
        if(obj1.size > obj2.size) {
            return NSOrderedAscending;
        } else if (obj1.size < obj2.size) {
            return NSOrderedDescending;
        } else {
            return NSOrderedSame;
        }
    }];
    
    return sortedSymbols;
}

+ (NSArray *)sortModulesResults:(NSArray<ModuleResult *> *)moduleResults {
    NSArray *sortedModules = [moduleResults sortedArrayUsingComparator:^NSComparisonResult(ObjectResult *  _Nonnull obj1, ObjectResult *  _Nonnull obj2) {
        if(obj1.size > obj2.size) {
            return NSOrderedAscending;
        } else if (obj1.size < obj2.size) {
            return NSOrderedDescending;
        } else {
            return NSOrderedSame;
        }
    }];
    
    for (ModuleResult *moduleResult in moduleResults) {
        [moduleResult sortObjects];
    }
    
    return sortedModules;
}

@end
